import { createRouter, createWebHistory } from 'vue-router'
import Guard from './Guard'
import userImg from '@/assets/img/user.png'
import ratingImg from '@/assets/img/rating.png'
import settingImg from '@/assets/img/setting.png'

const router = createRouter({
  history: createWebHistory(import.meta.env.BASE_URL),
  routes: [
    {
      path: '/',
      redirect: '/login',
    },
    {
      path: '/login',
      name: 'login',

      meta: {
        auth: false,  //导航守卫 false表示不需要登录 true表示需要登录
      },
      component: () => import('@/views/Login/index.vue')
    },
    {
      path: '/load', //加载页面
      name: 'load',
      meta: {
        auth: true
      },
      component: () => import('../views/load/index.vue')
    },
    {
      path: '/main',
      name: 'main',
      redirect: '/main/PresonalPage',
      meta: {
        auth: true,  //导航守卫 false表示不需要登录 true表示需要登录
      },
      component: () => import('@/views/Main/index.vue'),
      children: [
        {
          path: '/main/PresonalPage',
          name: 'PresonalPage',
          component: () => import('@/views/Main/PresonalPage/PresonalPage.vue'),
        },
        {
          path: '/main/Community',
          name: 'Community',
          component: () => import('@/views/Main/Community/Community.vue'),
        },
        {
          path: '/main/setting',
          name: 'setting',
          redirect: '/main/setting/personSetting',
          component: () => import('@/views/Main/Setting/index.vue'),
          children: [
            {
              path: '/main/setting/personSetting',
              name: 'personSetting',
              title: '个人设置',
              meta: {
                role: [0, 1, 2]
              },
              icon: userImg,
              component: () => import('@/views/Main/Setting/components/PersonSetting.vue')
            },
            {
              path: '/main/setting/classSetting',
              name: 'classSetting',
              title: '班级设置',
              meta: {
                role: [1]
              },
              icon: ratingImg,
              component: () => import('@/views/Main/Setting/components/ClassSetting/ClassSetting.vue')
            },
            {
              path: '/main/setting/adminSetting',
              name: 'adminSetting',
              title: '管理员设置',
              icon: settingImg,
              meta: {
                role: [0, 1]
              },
              redirect: '/main/setting/adminSetting/classManage',
              component: () => import('@/views/Main/Setting/components/AdminSetting/AdminSetting.vue'),
              children: [
                {
                  path: '/main/setting/adminSetting/classManage',
                  name: 'classManage',
                  title: '班级管理',
                  meta: {
                    role: [0, 1]
                  },
                  component: () => import('@/views/Main/Setting/components/AdminSetting/ClassManage.vue')
                },
                {
                  path: '/main/setting/adminSetting/teacherManage',
                  name: 'teacherManage',
                  title: '教师管理',
                  meta: {
                    role: [0, 1]
                  },
                  component: () => import('@/views/Main/Setting/components/AdminSetting/TeacherManage.vue')
                }
              ]
            }
          ]
        }
      ]
    },
    { // 这是临时使用
      path: '/',
      redirect: '/main'
    },
    {
      path: '/DetailPage/:id',
      name: 'DetailPage',
      title: '学生',
      icon: '/src/assets/img/个人设置.png',
      component: () => import('@/views/Main/DetailPage/DetailPage.vue')

    },
    {
      path: '/TeachPage/:id',
      name: 'TeachPage',
      title: '老师',
      icon: '/src/assets/img/个人设置.png',
      component: () => import('@/views/Main/TeachPage/TeachPage.vue')

    },
    {
      path: '/ClassPage/:id',
      name: 'ClassPage',
      title: '班级',
      icon: '/src/assets/img/个人设置.png',
      component: () => import('@/views/Main/ClassPage/ClassPage.vue')

    },
  ]
})

export {
  router,
  Guard
}
